/**
 * admui-basic v2.1.0 (http://www.admui.com/)
 * Copyright 2015-2019 Admui Team
 * Licensed under the Admui License 1.1 (http://www.admui.com/about/license)
 */
(function(window, document, $) {
  'use strict';

  /* global _ */

  window.App.extend({
    run: function() {
      $.fn.dataTable.ext.search.push(function(settings, data) {
        var min = parseInt($('#DTMinAge').val(), 10);
        var max = parseInt($('#DTMaxAge').val(), 10);
        var age = parseFloat(data[3]) || 0;
        var table;

        table = $('#dataTableExample').DataTable($.concatCpt('dataTable'));

        $('#admui-pageContent').on('keyup', '#DTMinAge, #DTMaxAge', function() {
          table.draw();
        });

        return (
          (_.isNaN(min) && _.isNaN(max)) ||
          (_.isNaN(min) && age <= max) ||
          (min <= age && _.isNaN(max)) ||
          (min <= age && age <= max)
        );
      });
    }
  });
})(window, document, jQuery);
